//
//  JZHISViewController.m
//  极致荟
//
//  Created by hetao on 14-8-19.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHISViewController.h"

@interface JZHISViewController ()

@end
int nuber;
@implementation JZHISViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
    nuber=0;
    self.navigationItem.title=@"个性签名";
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    [self.contenttexit becomeFirstResponder];
    [self.contenttexit setReturnKeyType:UIReturnKeyDone];
    [self.contenttexit setText:[User defuceUser].isStr];
    nuber=self.contenttexit.text.length;
    self.nuber.text=[NSString stringWithFormat:@"%d",30-nuber];
    
}

- (void)leftDrawerButtonPress:(UIButton *)but
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if([text isEqualToString:@"\n"])
    {
        [self update:textView.text];
        return NO;
    }
    if(range.length==1)
    {
        return YES;
    }
   
    if(nuber+1>30)
    {
        return NO;
    }
    

    return YES;
}
- (void)textViewDidChangeSelection:(UITextView *)textView
{
    nuber=textView.text.length;
    self.nuber.text=[NSString stringWithFormat:@"%d",30-nuber];
    NSLog(@"%d",textView.text.length);
}

-(void)update:(NSString *)text
{
      [self.navigationController popViewControllerAnimated:YES];
    NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:[User defuceUser].userId],@"userId",@"Sign",@"infoType",text,@"editInfo",nil];
    [User defuceUser].isStr=text;
    [HttpRequest httpRequestPost:JZHHTTPURL(@"myInformation/editInfo") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        NSLog(@"%@",data);
    }];

}
@end
